package algorithms.question.class15;

import common.util.MyUtil;

/**
 * https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/
 *
 * @author guichang
 * @date 2021/8/14
 */

@SuppressWarnings("all")
public class Code2_股票问题2 {

    public static void main(String[] args) {
        int[] arr = MyUtil.createArray(7, 1, 5, 3, 6, 4);
        MyUtil.print(maxProfit(arr));
    }

    public static int maxProfit(int[] prices) {
        if (prices == null || prices.length < 2) {
            return 0;
        }

        int max = 0;
        for (int i = 1; i < prices.length; i++) {
            max += Math.max(0, prices[i] - prices[i - 1]);
        }
        return max;
    }
}